﻿using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Battle.Engine.LogicModel
{
    public class FTalent
    {
        public string id;
        public string group; //天赋所在天赋组
        public List<string> immuneTalentGroup; // 免疫天赋组
        public List<string> immuneBuffGroup; // 免疫buff组
        public List<FTalentBuff> talentBuffs; // 天赋所带buff

        public FActor actor; //天赋所有者
        public EngineData engineData;

        public void init(FActor actor, string id, EngineData data)
        {
            this.actor = actor;
            this.engineData = data;
            this.id = id;

            TableTalent tData = this.engineData.tableDataUtil.GetTableTalent(id);
            this.group = tData.Group;
            //免疫天赋组
            immuneTalentGroup = new List<string>();
            if (tData.ImmuneTalentGroup.Length > 0)
            {
                string[] talentGroups = tData.ImmuneTalentGroup.Split(',');
                for(int i = 0; i<talentGroups.Length; i++)
                {
                    immuneTalentGroup.Add(talentGroups[i]);
                }
            }
            if(immuneTalentGroup.Count> 0)
            {
                this.actor.stateManager.immuneTalentGroup.AddRange(immuneTalentGroup);
            }
            //免疫buff组
            immuneBuffGroup = new List<string>();
            if (tData.ImmuneBuffGroup.Length > 0)
            {
                string[] buffGroups = tData.ImmuneBuffGroup.Split(',');
                for (int i = 0; i < buffGroups.Length; i++)
                {
                    immuneBuffGroup.Add(buffGroups[i]);
                }
            }
            if (immuneBuffGroup.Count > 0)
            {
                this.actor.stateManager.immuneBuffGroup.AddRange(immuneBuffGroup);
            }
            //天赋buff
            this.talentBuffs = new List<FTalentBuff>();
            for (int i = 0; i < tData.Buff_array.Length; i++)
            {
                if (!string.IsNullOrEmpty(tData.Buff_array[i]))
                {
                    TableBuff tBuffData = this.engineData.tableDataUtil.GetTableBuff(tData.Buff_array[i]);
                    if (tBuffData != null)
                    {
                        var talentBuff = new FTalentBuff(this, tData.Buff_array[i], (TalentBuffTriggerTimer)tData.BuffTriggerTimer_array[i],
                            (BuffTriggerCondition)tData.BuffTriggerCondition_array[i], tData.BuffConditionArgs_array[i], tData.BuffPercent_array[i], tData.BuffSelect_array[i]);
                        this.talentBuffs.Add(talentBuff);
                    }
                }
            }
        }

    }
}
